<?php
class Footer_Data {
	
	private $db;
	
	public function __construct(){
		$this->db = new MysqlImproved_Driver();
	}
	
	public function getFooterData(){
		$this->db->connect();
		$this->db->prepare(
				"
				SELECT
				modules_settings.module_sitename,
				modules_settings.module_siteurl,
				meta_modules.module_link_title,
				meta_modules.module_link_alt
				FROM
				modules_settings,
				meta_modules
				WHERE
				modules_settings.module_sitename = meta_modules.module_sitename
				;
				"
				);
		$this->db->query();
		$footer = "";
		while($footerData = $this->db->fetch('array')){
			$footer .= "<p>";
			$footer .= '<a title="';
			$footer .= $footerData['module_link_title'];
			$footer .= '" alt="';
			$footer .= $footerData['module_link_alt'];
			$footer .= '" href="';
			$footer .= SITE_ROOT . '/' . $footerData['module_siteurl'];
			$footer .= '" rel="external">';
			$footer .= $footerData['module_sitename'];
			$footer .= "</a> -> ";
			$footer .= $this->itemData($footerData['module_sitename']);
			$footer .= "</p>";
		}
		return $footer;
	}
	
	public function itemData($module_sitename){
		$this->db->connect();
		$this->db->prepare(
				"
				SELECT
				category_settings.category_sitename,
				category_settings.module_sitename,
				category_settings.category_siteurl,
				meta_category.category_link_title,
				meta_category.category_link_alt
				FROM
				category_settings, 
				meta_category
				WHERE 
				meta_category.category_sitename = category_settings.category_sitename
				AND 
				category_settings.module_sitename = 'Login'
				;
				"
				);
		$this->db->query();
		$footerCategoryData = "";
		while($categoryData = $this->db->fetch('array')){
			$footerCategoryData .= '<a title="';
			$footerCategoryData .= $categoryData['category_link_title'];
			$footerCategoryData .= '" alt="';
			$footerCategoryData .= $categoryData['category_link_alt'];
			$footerCategoryData .= '" href="';
			$footerCategoryData .= SITE_ROOT . '/' . strtolower($categoryData['module_sitename']) . '/' .$categoryData['category_siteurl'];
			$footerCategoryData .= '" rel="external">';
			$footerCategoryData .= $categoryData['category_sitename'];
			$footerCategoryData .= '</a> '; 
		}
		return $footerCategoryData;
	}
}